package com.jk.bgrotation.service;

import com.jk.bgrotation.dao.UserDao;
import com.jk.bgrotation.entity.AdminMoEntity;
import com.jk.bgrotation.entity.GoodEntity;
import com.jk.bgrotation.entity.SlideShowEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServcie {
    @Resource
    private UserDao userDao;
    @Autowired
    private MongoTemplate mongoTemplate;


    //查询正常的图
    public List<SlideShowEntity> getList() {
        return  userDao.getList();
    }

    //回收站 查询不正常的图
    public List<SlideShowEntity> getList2() {
        return userDao.getList2();
    }

    //新增 正常 且下架的图
    public Map addShow(SlideShowEntity show) {
        GoodEntity good= userDao.findadd(show.getCommodityId());
        Map map=  new HashMap();
        if (good!=null){
            userDao.addShow(show);
            AdminMoEntity ad = new AdminMoEntity();
            ad.setWardenId(1);
            ad.setWardenNum("111");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            ad.setWardenDate(sdf.format(new Date()));
            ad.setWardenOperate("管理员刘国峰新增了名为"+show.getSlideshowImg()+"的图片");
            mongoTemplate.save(ad);//4566
            map.put("code",200);
        }else {
            map.put("code",201);
        }
        return map;
    }

    //回收站的恢复按钮 id为 slideshowId
    public void upstatus(Integer slideshowId) {
        userDao.upstatus(slideshowId);
    }

    //轮播图 操作 逻辑删除
    public void upShowStatus(Integer slideshowId) {
        userDao.upShowStatus(slideshowId);
    }

    //上架图片
    public void grounding(Integer slideshowId) {
        userDao.grounding(slideshowId);
    }

    //下架图片
    public void undercarriage(Integer slideshowId) {
        userDao.undercarriage(slideshowId);
    }

    //事件
    public Map on(Integer commodityId) {
        GoodEntity good= userDao.findadd(commodityId);
        Map map=  new HashMap();
        if (good!=null){
            map.put("code",200);
        }else {
            map.put("code",201);
        }
        return map;
    }




}
